//
//  main.cpp
//  下标运算符
//
//  Created by linjinzhu on 2017/7/12.
//  Copyright © 2017年 baidu. All rights reserved.
//

#include <iostream>

using namespace std;
const int SIZE = 10;

class SafeArray {
private:
public:
    int arr[SIZE];
    SafeArray() {
        for (int i=0; i<SIZE; i++) {
            arr[i] = i;
        }
    }

    int &operator[](int i) {
        if (i >= SIZE) {
            cout << "index is out of bounds" << endl;
            return arr[0];
        }

        return arr[i];
    }
};

int main(int argc, const char * argv[]) {

    SafeArray A;

    for (int i=0; i<20; i++) {
        cout << &A[i] << endl;
        cout << &(A.arr)+i << endl;
    }

    return 0;
}
